SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE dbo.DnnProduct_UnRegisterAssembly
	@PackageID     int,
	@AssemblyName   nvarchar(250)
AS
	DECLARE @ReturnCode bit
	SET @ReturnCode = 1 -- 1 = Can Delete Assembly, 0 = Cannot Delete Assembly

	-- First remove the Assembly Reference for this Package
	DELETE FROM dbo.DnnProduct_Assemblies
		WHERE PackageID = @PackageID
			AND AssemblyName = @AssemblyName

	-- Next check if any other Package is using this assembly
	SET @PackageID = (SELECT TOP 1 PackageID 
							FROM dbo.DnnProduct_Assemblies
							WHERE AssemblyName = @AssemblyName)

	IF @PackageID IS NOT NULL
		-- Set ReturnCode = 0, so assembly is not deleted
		SET @ReturnCode = 0

	SELECT @ReturnCode
GO
